package org.aeon.client.view.components.sessionPanel;

import org.aeon.entity.dto.GroupInfoDto;
import org.aeon.entity.dto.UserInfoDto;
import org.aeon.utils.SwingUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author: MissingAeon
 * @date: 2024/2/20 19:01
 * @description:
 */
public class ChatTopPanel extends JPanel {
    final JLabel label;

    public ChatTopPanel() {
        final Dimension preferredSize = new Dimension(700, 50);
        SwingUtil.setSize(this, preferredSize);

        this.setLayout(null);

        label = new JLabel();
        label.setFont(new Font("黑体", Font.PLAIN, 22));
        this.add(label);

        final JButton button = new JButton("···");
        button.setContentAreaFilled(false);
        button.setBorder(null);
        button.setBounds(650, 0, 50, 50);
        button.setFont(new Font("隶书", Font.BOLD, 7));
        this.add(button);
    }

    public void setText(String text) {
        label.setText(text);
        Font font = label.getFont();
        // 获取字符串的宽度和高度
        label.setBounds(20, 15, SwingUtil.getStringWidth(text, font) + 20,
                SwingUtil.getStringHeight(text, font));
    }

    public void load(UserInfoDto user) {
        this.setText(user.getNickname());
        //  TODO 更多選項
    }

    public void load(GroupInfoDto group) {
        this.setText(group.getGroupName());
        //  TODO 更多選項
    }
}
